<?php
namespace Admin\Controller;
use Admin\Controller;
/**
 * 单页管理
 */
class ContactController extends BaseController
{

    public function index(){
        $article = M('contact_art')->order('id desc')->limit(0,1)->select();
        foreach ($article as $v){
            $artArr[] = $v;
        }
//        var_dump($artArr);
        $this->assign('artArr',$artArr);

        $file = M('contact_pho')->order('id desc')->limit(0,1)->select();
        foreach ($file as $v){
            $imgArr[] = $v;
        }
//        var_dump($imgArr);
        $this->assign('imgArr',$imgArr);
        $this->display();
    }

    public function contact_upload(){
        if ($_POST['submit']=='更新文字'){
            $text = M('contact_art');
            $data = array(
                'producer' => $_POST['producer'],
                'address' => $_POST['address'],
                'tel' => $_POST['tel'],
                'email' => $_POST['email'],
            );
                if($pd = $text->add($data)){
                    $this->success('更新成功!');
                }
        }

        if($_POST['submit']=='更新图片'){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 3145728 ;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型

            // 上传文件01
            $info = $upload->upload();
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功
                $data = array(
                    'filename' => $info['photo']['savename'],
                    'fileurl' => $info['photo']['savepath'],
                    'pid' => 1,
                );
                if ($pd = M('contact_pho')->add($data)){
                    $this->success('上传成功！');
                }
            }
        }

    }

}